/*
 * FileDetailsTableModel.java
 *
 * Created on 14 April 2007, 21:47
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.cardcopier.ui;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import org.cardcopier.file.FileState;
import org.cardcopier.file.FileUtils;

/**
 *
 * @author Mark
 */
public class FileDetailsTableModel extends AbstractTableModel {

    public static final String FILE_NAME_COLUMN = "File name";
    public static final String SIZE_COLUMN = "Size";
    public static final String MODIFIED_DATE_COLUMN = "Modified";
    public static final String STATUS_COLUMN = "Status";
    
    private final String[] columnHeadings = {
        FILE_NAME_COLUMN,
        SIZE_COLUMN,
        MODIFIED_DATE_COLUMN,
        STATUS_COLUMN
    };
    
    private List<FileState> fileStates;
    
    public FileDetailsTableModel() {
        setFileStates(new ArrayList<FileState>());
    }

    public void setFileStates(List<FileState> fileStates) {
        this.fileStates = fileStates;
        fireTableDataChanged();
    }
    
    public boolean fileExistsInDestination(int row) {
        return fileStates.get(row).fileExistsInDestination();
    }
    
    public FileState getFileStateAt(int row) {
        return fileStates.get(row);
    }
    
    public int getRowCount() {
        return fileStates.size();
    }

    public int getColumnCount() {
        return columnHeadings.length;
    }

    public String getColumnName(int column) {
        return columnHeadings[column];
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        FileState row = fileStates.get(rowIndex);
        if (columnIndex == 0) {
            return row.getName();
        } else if (columnIndex == 1) {
            return row.getFileLengthInBytes();
        } else if (columnIndex == 2) {
            return row.getLastModified();
        } else if (columnIndex == 3) {
            return row.fileExistsInDestination();
        } else {
            throw new IllegalArgumentException("column index [" + columnIndex + "] is too big");
        }
    }

}
